package iserver

import (
	"src/zeus/dbservice"
	"src/zeus/msgdef"
	"time"
)

// IEntity 实体接口
type IEntity interface {
	IEntityPanic
	// 消息传递
	Post(srvType uint8, msg msgdef.IMsg) error
	// DelayPost 延迟发送消息, 在帧尾发送
	DelayPost(srvType uint8, msg msgdef.IMsg) error
	// 快速消息调用
	RPC(srvType uint8, methodName string, args ...interface{}) error
	//RPCOther(srvType uint8, srcEntityID uint64, methodName string, args ...interface{}) error

	// 获取实体类型
	GetType() string
	GetID() uint64
	GetDBID() uint64
	AddGroup(g string)
	DelGroup(g string)
	GetGroups() interface{}
	GetGroup(g string) (interface{}, bool)
	GetRealPtr() interface{}
	GetInitParam() interface{}
	GetSrvIDS() []*dbservice.EntitySrvInfo
	GetEntitySrvID(srvType uint8) (srvId uint64, spaceId uint64, err error)
	//是否存在与指定的服务器上
	IsExistSID(srvid uint64) bool

	GetProxy() IEntityProxy

	// EnterSpace(spaceID uint64)
	// LeaveSpace()
	// LeaveSpaceByID(spaceID uint64)
	GetSpaceID() uint64
	IsOwnerSpaceEntity() bool
	IsSpaceEntity() bool
	IsDestroyed() bool
	SetOnDestroyCallback(f func())
	// 是否加载失败，如果失败，后面的逻辑就不继续下去了
	GetIsFailLoad() bool
	// 获取当前时间
	GetNowTime() time.Time

	//设置加载失败 是否加载失败，如果失败，后面的逻辑就不继续下去了
	SetLoadFail()
}

type IEntityPanic interface {
	OnPanic(err error)
	//实体字符串化
	String() string
}

const (
	Entity_State_Init = iota
	Entity_State_Loop
	Entity_State_Destroy
	Entity_State_InValid
	//暂停状态
	Entity_State_Suspend
	// 进入回收状态，运行完成后会进入Entity_State_Suspend
	Entity_State_SetRecycle
)

// IEntityStateGetter 获取Entity状态
type IEntityStateGetter interface {
	GetEntityState() uint32
	SetEntityState(st uint32)
}
